<template>
	<view class="content bg-img bg-mask" v-if="show">
		<view class="head flex flex-direction  align-center ">
			<image src="../../static/head.png" mode="scaleToFill" class="margin-right-xs"></image>
			<text class="t1">Preacher-PEC</text>
			<text class="t2 margin-top">PEC community preaching PEC head mine</text>
			<text class="t2">computing power</text>
		</view>
		<view class="flex justify-center base" style="padding: 100rpx;">
			<view class="animation cuIconfont-spin"><!--  --></view>
			<view class="qiyuan1 flex align-center flex-direction justify-center">
				<text class="t1">{{ i18n.invite.i1 }}</text>
				<view class="radius flex align-center justify-center">
					<input
						type="text"
						value=""
						v-model="parent_address"
						:placeholder="i18n.invite.i2"
						placeholder-class="inputS"
					/>
				</view>
				<image src="../../static/jiantou.png" mode="" @click="logIn"></image>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			parent_address: '',
			show: true
		};
	},

	onLoad() {
		var obj = setInterval(() => {
			if (window.tronWeb) {
				clearInterval(obj);

				this.show = true;
			} else {
				this.show = false;
			}
		}, 20);
	},
	computed: {
		i18n() {
			return this.$t('message');
		}
	},
	methods: {
		async logIn() {
			if (!this.parent_address) return uni.$showMsg(this.i18n.invite.i4);
			if (window.tronWeb) {
				//this.dd()
				console.log(
					'window.tronWeb.isAddress(this.parent_addres) :>> ',
					window.tronWeb.isAddress(this.parent_address)
				);

				//TN23ychnxyGbeSTEuCyWkWZntXHP1gBunN

				var isShow = window.tronWeb.isAddress(this.parent_address);
				console.log('isShow :>> ', isShow);
				if (!isShow) {
					this.parent_address = '';
					return uni.$showMsg(this.i18n.invite.i5);
				} else {
					let obj = {
						address: uni.getStorageSync('uid'),
						parent_address: this.parent_address
					};
					const res = await this.$u.post('/index.php/api/auth/register', obj, {});
					if (res.code == 1) {
						console.log('res111111 :>> ', res.data.userinfo.token);
						
						uni.setStorageSync('token', res.data.userinfo.token);
						
						
						
						uni.reLaunch({
							url: './lnk'
						});
						
					} else {
						//uni.$showMsg(res.msg);
					}
				}
			} else {
			}

			// let obj = {
			// 	address: uni.getStorageSync('uid'),
			// 	parent_address: this.parent_address,
			// };
			// const res = await this.$u.post('/index.php/api/auth/register', obj, {});
			// if (res.code == 1) {
			// 	uni.setStorageSync('token', res.token);
			// } else {
			// 	uni.$showMsg(res.msg);
			// }
		}
	}
};
</script>

<style lang="scss" scoped>
.content {
	width: 100vw;
	height: 100vh;
	background-image: url(../../static/bgImg1.png);

	.head {
		padding-top: 110rpx;
		image {
			width: 102rpx;
			height: 90rpx;
		}
		.t1 {
			font-size: 60rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #fefefe;
		}
		.t2 {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #cccccc;
		}
	}
	.qiyuan1 {
		width: 500rpx;
		height: 500rpx;
		border: 6rpx solid rgba(0, 222, 185, 0.4);
		border-radius: 50%;
		/deep/.t1 {
			font-size: 26rpx;
			font-family: PingFang SC;

			color: #ffffff !important;
		}
		.radius {
			//margin: 48rpx 55rpx 0rpx;
			margin-top: 48rpx;
			margin-bottom: 55rpx;
			width: 420rpx;
			height: 60rpx;
			background: #ffffff;
			// opacity: 0.3;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			/deep/ input {
				//color: #ffffff !important;
				line-height: 1;
			}
			/deep/.inputS {
				display: flex;
				align-items: center;
				//color: #cccccc !important;
				font-size: 30rpx;
			}
		}
		image {
			width: 84rpx;
			height: 76rpx;
		}
	}
}
</style>
